﻿using BarManager.Core.BusinessRules.Interfaces.Specification;
using BarManager.Core.DomainService;
using BarManager.Core.Entity;
using System.Collections.Generic;

namespace BarManager.Core.BusinessRules.Specification
{
    public class ZonaAddSpecification : BaseSpecification<Zona>, IZonaSpecification
    {
        private Zona Zona = null;

        public ZonaAddSpecification(IZonaRepository repository)
            :base(repository)
        {
        }

        public override bool IsSatisfiedBy(Zona entity)
        {
            if(entity.Id == 0)
                Zona = BaseRepository.Get(x => x.Descripcion == entity.Descripcion);
            else
                Zona = BaseRepository.Get(x => x.Descripcion == entity.Descripcion && x.Id != entity.Id);
            return (Zona == null);
        }

        public override IEnumerable<string> GetErrorMessage()
        {
            if (Zona != null) yield return string.Format("Ya existe una zona con el nombre {0}", Zona.Descripcion);
            yield break;
        }
    }
}
